package com.ytktt.study.week12.task4.controller;

import com.ytktt.study.week12.task4.Order;
import com.ytktt.study.week12.task4.api.ProducerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单 rest 接口
 *
 * @author ytk
 */
@Slf4j
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

    private final ProducerService producerService;

    @PostMapping("/handler")
    public String handleOrder(@RequestBody Order order) {
        log.info("gen orderId: {}, userId: {}", order.getId(), order.getUserId());
        this.producerService.send(order);
        return "success";
    }
}
